<?php

namespace App\Enums\OpenShop;

class BaseErrorCode
{
    const  BASE_CODE_INSERT_FAIL = '100001';
    const  BASE_CODE_UPDATE_FAIL = '100002';
    const  BASE_CODE_DETAIL_FAIL = '100003';
    const  BASE_CODE_LIST_FAIL   = '100004';
    const  BASE_CODE_LOCK_TYPE_FAIL = '100005';


    const BASE_CODE_CN = [
        self::BASE_CODE_INSERT_FAIL => '添加失败',
        self::BASE_CODE_UPDATE_FAIL => '更新失败',
        self::BASE_CODE_DETAIL_FAIL => '查看详情失败',
        self::BASE_CODE_LIST_FAIL   => '查看列表失败',
        self::BASE_CODE_LOCK_TYPE_FAIL   => 'lockType错误',
    ];

    const CODE_CN = [];

    /**
     * @param $code
     * @return array|mixed|string
     */
    public static function getCodeMsg($code)
    {
        $errCodeMap = self::BASE_CODE_CN + static::CODE_CN;
        return $errCodeMap[$code] ?? "";
    }

    /**
     * @param $code
     * @return array
     */
    public static function errCodeTrans($code, string $msg = ''): array
    {
        return [$code, $msg ?: static::getCodeMsg($code)];
    }

}
